/***************************************************************************
 *  WlanSavvy
 *  Copyright  2007  Deepak Manoharan
 *  Email deepakm@gmail.com
 *  http://wlansavvy.googlecode.com/
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gnome.h>
#include <glade/glade.h>
#include "panellist.h"
#include "wl_if.h"

/* callback function prototypes */
static gint delete_event_cb(GtkWidget* w, GdkEventAny* e, gpointer data);
static gint destroy_cb(GtkWidget* w, GdkEventAny* e, gpointer data);

GtkWidget *app_window;
GladeXML *xml;

gint refresh_graph_callback(gpointer data)
{
	refresh_graph();
	return 1;
}

gint refresh_info_callback(gpointer data)
{
	refresh_if_info();
	return 1;
}

gint refresh_stats_callback(gpointer data)
{
	refresh_if_statistics();
	return 1;
}

int main (int argc, char *argv[])
{

	#ifdef ENABLE_NLS
		bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
		textdomain (PACKAGE);
	#endif

	gnome_init (PACKAGE, VERSION, argc, argv);
	glade_gnome_init ();
	/*
	 * The .glade filename should be on the next line.
	 */
	xml = glade_xml_new (PACKAGE_SOURCE_DIR"/WlanSavvy.glade", NULL, NULL);

	/* This is important */
	glade_xml_signal_autoconnect (xml);
	app_window = glade_xml_get_widget (xml, "WlanSavvy");
	
    /* Connect signals for termination of application */
    g_signal_connect(G_OBJECT(app_window), "delete_event",
                G_CALLBACK(delete_event_cb), NULL);

    g_signal_connect(G_OBJECT(app_window), "destroy",
                G_CALLBACK(destroy_cb), NULL);
				
	
	/*Load interfaces available*/
	//TODO: If no interfaces found what do I do ???
	load_wlan_interfaces();
	
	gtk_widget_show (app_window);
	init_panel_list();

	gtk_timeout_add(100, refresh_stats_callback, NULL);
	gtk_timeout_add(1000, refresh_info_callback, NULL);
	gtk_timeout_add(1000, refresh_graph_callback, NULL);
	
	init_wlif();
	refresh_info_callback(NULL);
	refresh_stats_callback(NULL);
	refresh_graph_callback(NULL);
	
	gtk_main ();
	return 0;
}


static gint delete_event_cb(GtkWidget* w, GdkEventAny* e, gpointer data)
{
    /* callback for "delete" signal */
    g_print("main.c:delete_event_cb()\n");
    return 0;
}

static gint destroy_cb(GtkWidget* w, GdkEventAny* e, gpointer data)
{
    /* callback for "destroy" signal */
    g_print("main.c:destroy_cb()\n");

    /* quit application */
    gtk_main_quit();
    return 0;
}
